package com.yanqu.road.server.cmd.manor.fishpond;

import com.yanqu.road.pb.manor.FishPondProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.manor.ManorFishPondModel;
import com.yanqu.road.server.gameplayer.module.manor.ManorModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.List;

/**
 * @author ：zfr
 * @date ：2021/10/12 16:14
 */
@Cmd(code = GameProtocol.S_FISH_POND_SET_SHOW_FISH_LIST, desc = "鱼塘设置展示鱼群")
public class SetShowFishListCmd extends AbstractCommand {
    private List<Integer> fishIdList;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        FishPondProto.SetShowFishListReqMsg reqMsg = FishPondProto.SetShowFishListReqMsg.parseFrom(packet.getBytes());
        fishIdList = reqMsg.getFishIdList();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ManorFishPondModel manorFishPondModel = player.getModule(ManorModule.class).getManorFishPondModel();
        if (manorFishPondModel != null) {
            ret = manorFishPondModel.setShowFish(fishIdList);
        } else {
            ret = GameErrorCode.E_FISH_POND_IS_LOCK;
        }
    }

    @Override
    public void sendData(GamePlayer player) {
        FishPondProto.SetShowFishListRespMsg.Builder respMsg = FishPondProto.SetShowFishListRespMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(ClientProtocol.U_FISH_POND_SET_SHOW_FISH_LIST, respMsg);
    }
}
